import "reflect-metadata";
import { createConnection } from "typeorm";
const env = process.env.NODE_ENV;
export default async function connectionDatabse() {
    const connection = await createConnection({
        type: "mysql",
        host: "localhost",
        port: 3306,
        username: "root",
        password: "123456",
        database: "storeDB",
        // synchronize: env === 'development',//true同步创建列  （开发阶段使用）
        synchronize: false,
        cache: false,  //开启查询缓存
        // entities:[`${env === 'development' ? 'src/' : 'dist/src/'}api/entity/*{.js,.ts}`],
        entities: [__dirname + `/../api/entity/*{.js,.ts}`],
        logging: ["query", "error"],
        logger: "file",
        migrationsTableName: "migration_table",
        migrations: [
            __dirname + "/migrations/*{.js,.ts}"
        ],
        cli: {
            "migrationsDir": "migration"
        }
    })

    return connection;
}